#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdio>
#include <errno.h>
#include <cstdlib>


// 读取文件，写入命名管道
int main()
{
    mkfifo("fifo", 0644);
    int infd = open("log.txt", O_RDONLY);
    if (infd < 0)
    {
        perror("open");
        return 1;
    }

    int outfd = open("fifo", O_WRONLY);
    if (outfd < 0)
    {
        perror("open");
        return 2;
    }

    char buf[1024];
    int n;
    while ((n = read(infd, buf, sizeof(buf))) > 0)
    {
        write(outfd, buf, n);
    }

    close(infd);
    close(outfd);

    return 0;
}
